load("//tools/build_defs/android:fb_core_android_library.bzl", "fb_core_android_library")
load("//tools/build_defs/oss:profilo_defs.bzl", "profilo_path")
load("//tools/build_defs/oss:profilo_sample_app.bzl", "profilo_sample_app")
load("//tools/build_defs:fb_native_wrapper.bzl", "fb_native")

fb_native.keystore(
    name = "keystore",
    properties = "sample.keystore.properties",
    store = "sample.keystore",
    visibility = [
        profilo_path("..."),
    ],
)

SAMPLE_LIB_SRCS = [
    "BaseSampleAppMainActivity.java",
    "WorkloadThread.java",
]

fb_native.android_build_config(
    name = "sample-buildconfig-dummy",
    package = "com.facebook.profilo",
    values = [
        "String[] PROVIDERS = new String[] { }",
    ],
)

fb_core_android_library(
    name = "sample-lib",
    srcs = SAMPLE_LIB_SRCS,
    provided_deps = [
        ":sample-buildconfig-dummy",
    ],
    visibility = [
        "PUBLIC",
    ],
    deps = [
        profilo_path("java/main/com/facebook/profilo/config:config"),
        profilo_path("java/main/com/facebook/profilo/controllers/external:external"),
        profilo_path("java/main/com/facebook/profilo/controllers/external/api:api"),
        profilo_path("java/main/com/facebook/profilo/core:core"),
        profilo_path("deps/soloader:soloader"),
    ],
)

ACTIVITY_SRCS = glob(
    ["*.java"],
    exclude = SAMPLE_LIB_SRCS,
)

fb_native.export_file(
    name = "aar-manifest",
    src = "AndroidManifest-aar.xml",
    visibility = [
        "PUBLIC",
    ],
)

profilo_sample_app(
    srcs = ACTIVITY_SRCS,
    aar_manifest = ":aar-manifest",
    app_manifest = "AndroidManifest-sample.xml",
    providers = None,
)

# Referred to by open source buckconfig, don't forget to update it there.
profilo_sample_app(
    srcs = ACTIVITY_SRCS,
    aar_manifest = ":aar-manifest",
    app_manifest = "AndroidManifest-sample.xml",
    providers = [
        "atrace",
        "stacktrace",
        "systemcounters",
        "threadmetadata",
    ],
)

profilo_sample_app(
    srcs = ACTIVITY_SRCS,
    aar_manifest = ":aar-manifest",
    app_manifest = "AndroidManifest-sample.xml",
    providers = [
        "atrace",
        "processmetadata",
        "stacktrace",
        "systemcounters",
        "threadmetadata",
    ],
)

# Generate a target for each individual provider
[
    profilo_sample_app(
        srcs = ACTIVITY_SRCS,
        aar_manifest = ":aar-manifest",
        app_manifest = "AndroidManifest-sample.xml",
        providers = [
            provider,
        ],
    )
    for provider in [
        "atrace",
        "processmetadata",
        "stacktrace",
        "systemcounters",
        "threadmetadata",
        "yarn",
    ]
]
